#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
#include <Cocoa/Cocoa.h>

@interface MyDelegate : NSObject
{
  NSWindow *myWindow;
  NSImage *myImage;
  NSImageView *myImageView;
}
//- (void) createMenu;
//- (void) createImageView;
- (void) createWindow;
- (void) applicationWillFinishLaunching: (NSNotification *)not;
- (void) applicationDidFinishLaunching: (NSNotification *)not;
@end

@implementation MyDelegate : NSObject 
- (void) dealloc
{
  RELEASE (myWindow);
  [super dealloc];
}

/*- (void) createMenu
{
  NSMenu *menu;

  menu = AUTORELEASE ([NSMenu new]);

  [menu addItemWithTitle: @"Quit"  
        action: @selector (terminate:)  
        keyEquivalent: @"q"];

  [NSApp setMainMenu: menu];

}*/
/*
- (void) createImageView
{
      NSImageView *imageView = [NSImageView alloc];
      myImage = [[NSImage alloc] initWithContentsOfFile:@"/home/bubble/objc/bubblehack/pics/t16tiles.png"];
      [imageView setImage:myImage];
      [myWindow addSubview:imageView];
      [imageView release];
}
*/
- (void) createWindow
{
  NSRect rect = NSMakeRect (0, 0, 640, 480);
  unsigned int styleMask = NSTitledWindowMask 
                           | NSMiniaturizableWindowMask;


  myWindow = [NSWindow alloc];
  myWindow = [myWindow initWithContentRect: rect 
                       styleMask: styleMask
                       backing: NSBackingStoreBuffered
                       defer: NO];
  [myWindow setTitle: @"bubblehack"];
      myImageView = [NSImageView new];
      myImage = [[NSImage new] initWithContentsOfFile:@"/home/bubble/objc/bubblehack/pics/t16tiles.png"];
      [myImageView setImage:myImage];
      [[myWindow contentView] addSubview:myImageView];
}

- (void) applicationWillFinishLaunching: (NSNotification *)not
{
  [self createWindow];
//  [self createMenu];
//  [self createImageView];
}

- (void) applicationDidFinishLaunching: (NSNotification *)not;
{
  [myWindow makeKeyAndOrderFront: nil];
}
@end

int main (int argc, const char **argv)
{ 
CREATE_AUTORELEASE_POOL(pool);
  id app;

  app = [NSApplication sharedApplication];
  [app setDelegate: [MyDelegate new]];
  [app run];
  RELEASE(pool);
  return 0;

}
